#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>

using namespace std;

// 1233. 删除子文件夹
// https://leetcode.cn/problems/remove-sub-folders-from-the-filesystem/description/?envType=daily-question&envId=2025-07-19

class Solution
{
public:
    vector<string> removeSubfolders(vector<string> &folder)
    {
        sort(folder.begin(), folder.end());
        unordered_set<string> ret;
        for (int i = 0; i < folder.size(); i++)
        {
            if (folder[i].size() <= 3)
            {
                ret.insert(folder[i]);
                continue;
            }
            string curFolder = folder[i];
            for (int i = 1; i < curFolder.size(); i++)
            {
                if (curFolder[i] == '/' )
                {
                    if(ret.find(curFolder.substr(0, i)) != ret.end()){
                        break;
                    }
                }
                if(i == curFolder.size() - 1){
                    ret.insert(curFolder);
                }
            }
        }
        vector<string> ans(ret.begin(), ret.end());
        return ans;
    }
};

int main()
{
    return 0;
}